package collection2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

/**
 * @Auther: 杨通通
 * @Date: 2024/10/26 00:32
 * @Description:
 */
public class list3 {
    public static void main(String[] args) {
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        list.add("a");
        list.add("v");
        int size = list.size();
        String[] arr = new String[list.size()];
        String[] array =  list.toArray(arr);
        Arrays.stream(arr).forEach(System.out::println);
        Arrays.stream(array).forEach(System.out::println);
        System.out.println(arr == array);


//        ArrayList<String> collect = list.stream().collect(Collectors.toCollection(ArrayList::new));
        //等价于上面的类方法
        ArrayList<String> collect = list.stream().collect(Collectors.toCollection(()->{
            return new ArrayList<>();
        }));

        ArrayList<String> list1 = new ArrayList<>();
        list1.get(3);


        List<String> collect1 = list.stream().collect(Collectors.toList());
    }
}